import copy

import pandas as pd
from fuzzywuzzy import fuzz
from fuzzywuzzy import process


df1 = pd.read_excel(rf'D:\Desktop\511\68.xlsx', index_col="项目名称")
df2 = pd.read_excel(rf'D:\Desktop\511\对比.xlsx', index_col="项目名称")
fw ="50-30"
fws = fw.split('-')
# df2 = copy.deepcopy(df1)
vals = list()
keys =list()
for i in df1.index:
    result = str()
    for j in df2.index:
        sore = fuzz.ratio(i, j)
        if int(fws[0]) > sore >= int(fws[1]):
            js = [c for c in j]
            jt = process.extract(i, js, limit=None)
            jtstr = str()
            for m in jt:
                if m[1] > 0:
                    jtstr = f'{jtstr}{m[0]}'
            # result = f'{result},{j}({sore})[{jtstr}]'
            result = f'{result},{j}'

    keys.append(i)
    if len(result) == 0:
        result =''
        vals.append(result)
    else:
        vals.append(result[1:])


mydata = dict()
mydata['项目名称'] = keys
mydata['匹配结果'] = vals
df = pd.DataFrame(mydata)

df.to_excel(rf'D:\Desktop\511\匹配数据{fw}.xlsx',index_label='项目名称')